<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>

<xsl:template match='nbsp' name='nbsp'>
<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>
</xsl:template>

<xsl:template match="nomore">
<table bgcolor="#f4efdf" class="nbox" border="0" cellspacing="0" cellpadding="4" width="100%">
<tr bgcolor="#f4ebce"><td height="25px"><b>Hai gia' risposto a tutti i test!</b></td></tr>
<tr bgcolor="#787878" height="1px"><td></td></tr>
<xsl:for-each select="iTest">
	<xsl:if test='position()&lt;5'>
<tr><td align="center"><a href="/tests/iTestResults.aspx?pollid={@form}"><xsl:value-of select="@title"/></a></td></tr>
	</xsl:if>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template match="iTest">
	<xsl:variable name="howmany">
		<xsl:value-of select="count(iTestResult)"/>
	</xsl:variable>
	<table bgcolor="#EFEFCE" class="body_10px" border="0" cellspacing="4" cellpadding="0" width="100%">
	<tr><td colspan="2"><xsl:value-of select="@question"/></td></tr>
	<tr height="5px"><td></td></tr>
	<xsl:for-each select="iTestResult">
		<xsl:if test='position()&lt;5'>
		<tr>
			<td><xsl:value-of select="@phits"/>%</td>
			<td><xsl:value-of select="@answer"/></td></tr>
		</xsl:if>
	</xsl:for-each>
	<xsl:if test='$howmany&gt;4'>
	<tr height="5px"><td colspan="2"></td></tr>
	<tr>
		<td colspan="2" align="center">
		<a href="/tests/iTestResults.aspx?form={@formid}"><b>Guarda tutte le <xsl:value-of select="$howmany"/> risposte!</b></a>
		</td></tr>
	</xsl:if>
	</table>
</xsl:template>

<xsl:template match="Registration">

<table bgcolor="#f4efdf" class="bbox" border="0" cellspacing="0" cellpadding="4" width="100%">
<form name="formRegistration" method="post" action="{@action}">
<input type="hidden" name="FORM_ID" value="{@ID}"></input>

<xsl:variable name="nextForm">
<xsl:for-each select="Question">
<xsl:choose>
	<xsl:when test='@Type="16"'>
			<xsl:value-of select="@P1"/>
	</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>

<xsl:for-each select="Question">
<xsl:choose>
	<xsl:when test='@Type="8"'>
		<tr><td class="nboxT" colspan="2" align="center">
		<input type="hidden" name="qTotal" value="{/Registration/@qTotal}"></input>
		<input type="hidden" name="yTotal" value="{/Registration/@yTotal}"></input>
		<input type="hidden" name="nextForm" value="{$nextForm}"></input>
		<br/><input type="submit" name="{concat('SUBMIT',@ID)}" value="{@Description}"></input><br/>
		</td></tr>
	</xsl:when>
	<xsl:otherwise>
		<tr><td bgcolor="#f4ebce" height="25px" colspan="2"><b><xsl:value-of select="@Description"/></b></td></tr>
		<tr bgcolor="#787878" height="1px"><td colspan="2"></td></tr>

		<xsl:if test='@Type="2"'>
		<xsl:variable name="radioID" select="concat('R',@ID)"></xsl:variable>
		<xsl:variable name="howmany">
			<xsl:value-of select="count(/Registration/Question/Answer)"/>
		</xsl:variable>

		<xsl:choose>
		<xsl:when test='@P1="1"'>
			<tr>
			<xsl:for-each select="Answer">
				<xsl:if test='position()&lt;6'>
					<xsl:choose>
					  <xsl:when test='@Selected="1"'><td class="nboxR"><input type="radio" checked="yes" value="{.}" name="{$radioID}"></input></td></xsl:when>
					  <xsl:when test='@Selected="0"'><td class="nboxR"><input type="radio" value="{.}" name="{$radioID}"></input></td></xsl:when>
					</xsl:choose>
					<td class="body_10px"><xsl:value-of select="."/></td>
				</xsl:if>
			</xsl:for-each>
			</tr>
			<xsl:if test='/Registration/@type="921" and $howmany&lt;4'>
			<tr><td class="nboxR"><input type="radio" value="new" name="{$radioID}"></input></td>
				<td class="nboxR"><INPUT onClick="document.formRegistration.{$radioID}[{$howmany}].click()" class="body_10px" TYPE="TEXT" SIZE="15" maxlength="100" NAME="answer2add"></INPUT></td>
			</tr>
			</xsl:if>
		</xsl:when>
		<xsl:when test='@P1="2"'>
			<xsl:for-each select="Answer">
				<xsl:if test='position()&lt;6'>
					<tr>
						<xsl:choose>
						  <xsl:when test='@Selected="1"'><td class="nboxR"><input type="radio" checked="yes" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
						  <xsl:when test='@Selected="0"'><td class="nboxR"><input type="radio" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
						</xsl:choose>
					<td  class="nboxR"><xsl:value-of select="."/></td>
					</tr>
				</xsl:if>
			</xsl:for-each>
			<xsl:if test='/Registration/@type="921" and $howmany&lt;4'>
			<tr><td class="nboxR"><input type="radio" value="new" name="{$radioID}"></input></td>
				<td class="nboxR"><INPUT onClick="document.formRegistration.{$radioID}[{$howmany}].click()" class="body_10px" TYPE="TEXT" SIZE="15" maxlength="100" NAME="answer2add"></INPUT></td>
			</tr>
			</xsl:if>
		</xsl:when>
		</xsl:choose>

		</xsl:if>

	</xsl:otherwise>
</xsl:choose>

</xsl:for-each>
<xsl:variable name="howmany">
	<xsl:value-of select="count(/Registration/Question/Answer)"/>
</xsl:variable>
<xsl:choose>
	<xsl:when test='($howmany&lt;6 and @type!="921") or ($howmany&lt;4)'>
		<tr><td class="nboxR" colspan="2" align="center">
		<input type="hidden" name="anon" value="{@anon}"></input>
		<input type="hidden" name="nextForm" value="{$nextForm}"></input>
		<br/><input type="submit" name="SUBMIT" value="Vota"></input><br/>
		</td></tr>
	</xsl:when>
	<xsl:otherwise>
		<tr><td class="nboxR" colspan="2" align="center">Guarda tutte le possibili risposte e vota!</td></tr>
	</xsl:otherwise>
</xsl:choose>

</form>
</table>

</xsl:template>

</xsl:stylesheet>